package by.pavlyukevich.paymentsystem.datamodel.card;

import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

import by.pavlyukevich.paymentsystem.datamodel.AbstractEntity;
import by.pavlyukevich.paymentsystem.datamodel.Account;
import by.pavlyukevich.paymentsystem.datamodel.user.UserAccount;

@Entity
public class Card extends AbstractEntity<Integer> {

	@ManyToOne(fetch = FetchType.LAZY, cascade = { CascadeType.REFRESH })
	@NotNull
	private Account account;

	@ManyToOne(fetch = FetchType.LAZY)
	@NotNull
	private UserAccount userAccount;

	@Column
	@NotNull
	private Boolean isBlocked;

	@Column
	@Min(value = 1000000000000000L)
	@Max(value = 9999999999999999L)
	private Long cardNumber;

	@OneToMany(mappedBy = "card", cascade = { CascadeType.ALL }, orphanRemoval = true)
	private Set<CardLimit> cardLimits;

	public Long getCardNumber() {
		return cardNumber;
	}

	public void setCardNumber(Long cardNumber) {
		this.cardNumber = cardNumber;
	}

	public Set<CardLimit> getCardLimits() {
		return cardLimits;
	}

	public void setCardLimits(Set<CardLimit> cardLimits) {
		this.cardLimits = cardLimits;
	}

	public Account getAccount() {
		return account;
	}

	public void setAccount(Account account) {
		this.account = account;
	}

	public UserAccount getUserAccount() {
		return userAccount;
	}

	public void setUserAccount(UserAccount userAccount) {
		this.userAccount = userAccount;
	}

	public Boolean getIsBlocked() {
		return isBlocked;
	}

	public void setIsBlocked(Boolean isBlocked) {
		this.isBlocked = isBlocked;
	}

}
